package com.sunny.shop.api.v1;

import com.sunny.shop.core.LocalUser;
import com.sunny.shop.core.interceptors.ScopeLevel;
import com.sunny.shop.dto.FeedbackDTO;
import com.sunny.shop.exception.httpe.Success;
import com.sunny.shop.model.Feedback;
import com.sunny.shop.model.User;
import com.sunny.shop.service.FeedbackServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Date;

@RestController
@RequestMapping("/feedback")
public class FeedbackController{
    @Autowired
    private FeedbackServiceImpl feedbackService;

    @ScopeLevel()
    @PostMapping()
    public void create(@RequestBody @Valid FeedbackDTO feedbackDTO){
        Long id = LocalUser.getUser().getId();
        Feedback feedback = new Feedback();
        feedbackDTO.setUid(id);
        BeanUtils.copyProperties(feedbackDTO, feedback);
        Date date = new Date();
        feedback.setCreateTime(date);
        feedbackService.create(feedback);
        throw new Success(90000);
    }
}
